# coding=utf-8

def get_fund_base_info():
    # 基金名称	代码	基金类型	基金规模	经理	成立日	管理人	评级	近1周	近1月	近3月	近6月	今年来	近1年	近2年	近3年
    name_dic = {}
    code_dic = {}
    with open('data_base_info.txt') as f:
        for line in f:
            line = line.decode('utf-8').strip().split()
            print len(line)
            name_dic[line[0]] = line
            code_dic[line[1]] = line
    return name_dic, code_dic


def get_compute():
    # 基金id	日收益率均值	年化波动率	年化收益率	m2测度	夏普率
    r = {}
    for line in open('data_compute.txt'):
        line = line.decode('utf-8').strip().split()
        info = {}
        info['code'] = line[0]
        info['day_avg'] = line[1]
        info['year_var'] = line[2]
        info['year_rate'] = line[3]
        info['m2'] = line[4]
        info['shap'] = line[5]
        r[line[0]] = info
    return r


def get_history_price():
    r = {}  # code: ([time], [price])
    for line in open('基金-历史价格.txt'):
        line = line.decode('utf-8').strip().split()
        if len(line) < 3:
            continue
        code = line[0]
        t = line[1]
        price = line[2]
        if code in r:
            (ts, ps) = r[code]
            ts.insert(0, t)
            ps.insert(0, price)
        else:
            ts = []
            #ts.append(t)
            ts.insert(0,t)
            ps = []
            #ps.append(price)
            ps.insert(0,price)
            r[code] = (ts, ps)

    return r

def not_money_rate():
    r = {}  # code: ([time], [price])
    for line in open('基金-历史价格.txt'):
        line = line.decode('utf-8').strip().split()
        if len(line) < 3:
            continue
        if line[0] == '000730':
            continue
        code = line[0]
        t = line[1]
        price = line[4].replace('%','')
        if code in r:
            (ts, ps) = r[code]
            ts.insert(0, t)
            ps.insert(0, price)
        else:
            ts = []
            ts.insert(0, t)
            ps = []
            ps.insert(0, price)
            r[code] = (ts, ps)

    return r

if __name__ == '__main__':
    print get_history_price()
